//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.itheima.service.impl;

import com.itheima.mapper.UserMapper;
import com.itheima.pojo.User;
import com.itheima.service.UserService;
import com.itheima.utils.Md5Util;
import com.itheima.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    public UserServiceImpl() {
    }

    public User findByUserName(String username) {
        User u = this.userMapper.findByUserName(username);
        return u;
    }

    public void register(String username, String password) {
        String md5String = Md5Util.getMD5String(password);
        this.userMapper.add(username, md5String);
    }

    public void update(User user) {
        this.userMapper.update(user);
    }

    public void updateAvatar(String avatarUrl) {
        Map<String, Object> map = (Map)ThreadLocalUtil.get();
        Integer id = (Integer)map.get("id");
        this.userMapper.updateAvatar(avatarUrl, id);
    }

    public void updatePwd(String newPwd) {
        Map<String, Object> map = (Map)ThreadLocalUtil.get();
        Integer id = (Integer)map.get("id");
        this.userMapper.updatePwd(Md5Util.getMD5String(newPwd), id);
    }
}
